//
//  SDHSportsLineupCell.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/12.
//

#import "SDHSportsLineupCell.h"
#import "SDHSportsTeamDataModel.h"
#import "UIImageView+YQAdd.h"

@interface SDHSportsLineupCell ()

@property (nonatomic, strong) UIImageView *avatarImg;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *descLb;

@end

@implementation SDHSportsLineupCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [[UIColor blackColor] addAlpha:0.7];
        [self initUI];
    }
    
    return self;
}

- (void)initUI {
    UIImageView *avatarImg = [UIImageView new];
    avatarImg.image = [UIImage imageNamed:@"touxiang"];
    [self.contentView addSubview:avatarImg];
    self.avatarImg = avatarImg;
    
    UILabel *nameLb = [UILabel new];
    nameLb.textAlignment = NSTextAlignmentLeft;
    nameLb.font = [UIFont systemFontOfSize:16];
    nameLb.textColor = [UIColor whiteColor];
    [self.contentView addSubview:nameLb];
    self.nameLb = nameLb;
    nameLb.text = @"G. Jianlu";
    
    UILabel *descLb = [UILabel new];
    descLb.textAlignment = NSTextAlignmentLeft;
    descLb.textColor = [UIColor whiteColor];
    descLb.font = [UIFont systemFontOfSize:14];
    descLb.numberOfLines = 0;
    [self.contentView addSubview:descLb];
    self.descLb = descLb;
    descLb.text = @"birthday: 1988-02-02\nheight: 177 weight: 72\nposition: forward\nnationality: Argentina\nsalary: 234 GBP\ngoal:1, assist: 1, yellow: 1, red: 0";
//    "img": "https://scoreimg.qiuhui.com/score/800a83d83e06c3e33fc185b25eeaeec6.jpg",
//                   "birth_date": "1988-02-02 00:00:00",
//                   "height": "177",
//                   "weight": "72",
//                   "position": "forward",
//                   "nationality": "Argentina",
//                   "salary": "234 GBP",
//                   "goal": 12,
//                   "assist": 1,
//                   "yellow": 0,
//                   "red": 0
    
    [avatarImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(15);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    
    [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatarImg.mas_right).offset(10);
        make.top.equalTo(avatarImg);
        make.right.mas_equalTo(-10);
    }];
    
    [descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLb);
        make.top.equalTo(nameLb.mas_bottom).offset(5);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-5);
    }];
}

- (void)updateContent:(id)obj {
    SDHSportsTeamDataPlayerModel *model = (SDHSportsTeamDataPlayerModel *)obj;
    [self.avatarImg setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    self.nameLb.text = model.en_name;
    NSString *birthday = model.birth_date.length > 0 ? [model.birth_date substringToIndex:10] : model.birth_date;
    self.descLb.text = [NSString stringWithFormat:@"birthday: %@\nheight: %@ weight: %@\nposition: %@\nnationality: %@\nsalary: %@\ngoal: %@, assist: %@, yellow: %@, red: %@", birthday, model.height, model.weight, model.position, model.nationality, model.salary, model.goal, model.assist, model.yellow, model.red];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
